<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>科研项目追踪</title>
    <!-- LOADING STYLESHEETS -->
    <link href="../css/bootstrap.css" rel="stylesheet">
    <link href="../css/font-awesome.min.css" rel="stylesheet">
    <link href="../css/style.css" rel="stylesheet">
    <style>
        .sort {
            float: right;
        }
    </style>
</head>

<body>
<!-- LOGO -->
<#--<div class="container">-->
<#--    <div class="row">-->
<#--        <div class="header">-->
<#--            <div class="logo">-->
<#--                &lt;#&ndash;        <img src="images/logo.png" alt="logo">&ndash;&gt;-->
<#--                场景三-->
<#--            </div>-->
<#--        </div>-->
<#--    </div>-->
<#--</div>-->
<#--<!-- END LOGO&ndash;&gt;-->

<!-- TOP NAVIGATION -->
<div class="container-fluid">
    <div class="navigation">
        <div class="row">
            <ul class="topnav">
                <li></li>
                <li>
                    <a href="/scidata/team">
                        <i class="fa fa-search-plus"></i>科研团队识别</a>
                </li>
                <li>
                    <a href="/scidata/project/all">
                        <i class="fa fa-location-arrow"></i>项目成果追踪</a>
                </li>
                <li>
                    <a href="/scidata/paper">
                        <i class="fa fa-book"></i>学科交叉分析</a>
                </li>
            </ul>
        </div>
    </div>
</div>
<!-- END TOP NAVIGATION -->

<!-- SEARCH FIELD AREA -->
<div class="searchfield bg-hed-six">
    <div class="container" style="padding-top: 20px; padding-bottom: 20px;">
        <div class="row text-center margin-bottom-20">
            <h1 class="white">科研项目追踪</h1>
        </div>
        <br>
        <div class="row search-row">
            <#if keyword??>
                <label for="keyword"></label><input id="keyword" type="text" class="search" placeholder="${keyword}" required maxlength="10">
            <#else>
                <label for="keyword"></label><input id="keyword" type="text" class="search" placeholder="请输入搜索内容" required maxlength="10">
            </#if>
            <button class="buttonsearch btn btn-info btn-lg" onclick="search()">搜索</button>
        </div>
    </div>
</div>
<!-- END SEARCH FIELD AREA -->

<!-- MAIN SECTION -->
<div class="container featured-area-default padding-30">
    <div class="row">
        <!-- SIDEBAR STUFF -->
        <div class="col-md-3 padding-20">

            <div class="row margin-top-20">
                <div class="col-md-12">
                    <div class="fb-heading-small">
                        按照学科领域筛选
                    </div>
                    <hr class="style-three">
                    <div class="fat-content-small padding-left-10">
                        <ul>
                            <li>
                                <label>
                                    <input type="radio" id="A" class="checkbox-inline" onclick="filterCode(this)">数理科学
                                </label>
                            </li>
                            <li>
                                <label>
                                    <input type="radio" id="B" class="checkbox-inline" onclick="filterCode(this)">化学科学
                                </label>
                            </li>
                            <li>
                                <label>
                                    <input type="radio" id="C" class="checkbox-inline" onclick="filterCode(this)">生命科学
                                </label>
                            </li>
                            <li>
                                <label>
                                    <input type="radio" id="D" class="checkbox-inline" onclick="filterCode(this)">地球科学
                                </label>
                            </li>
                            <li>
                                <label>
                                    <input type="radio" id="E" class="checkbox-inline" onclick="filterCode(this)">工程与材料科学
                                </label>
                            </li>
                            <li>
                                <label>
                                    <input type="radio" id="F" class="checkbox-inline" onclick="filterCode(this)">信息科学
                                </label>
                            </li>
                            <li>
                                <label>
                                    <input type="radio" id="G" class="checkbox-inline" onclick="filterCode(this)">管理科学
                                </label>
                            </li>
                            <li>
                                <label>
                                    <input type="radio" id="H" class="checkbox-inline" onclick="filterCode(this)">医学科学
                                </label>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>

            <div class="row margin-top-20">
                <div class="col-md-12">
                    <div class="fb-heading-small">
                        按照时间筛选
                    </div>
                    <hr class="style-three">
                    <div class="fat-content-small padding-left-10">
                        <label>
                            <input type="month" class="art-date" id="time" onchange="filterTime(this)">
                        </label>
                    </div>
                </div>
            </div>
        </div>
        <!-- END SIDEBAR STUFF -->

        <!-- ARTICLE OVERVIEW SECTION -->
        <div class="col-md-9 padding-20">
            <div class="row">
                <!-- BREADCRUMBS -->
                <div class="breadcrumb-container">
                    <ol class="breadcrumb">
                        <li>
                            <a href="/">
                                <i class="fa fa-home"></i>
                            </a>
                        </li>
                        <#if keyword?? && keyword != "">
                            <li><a class="btn btn-default btn-o btn-sm">${keyword}</a></li>
                        </#if>
                        <#if code??>
                            <#switch code>
                                <#case "A">
                                    <li><a class="btn btn-default btn-o btn-sm">数理科学</a></li>
                                    <#break >
                                <#case "B">
                                    <li><a class="btn btn-default btn-o btn-sm">化学科学</a></li>
                                    <#break >
                                <#case "C">
                                    <li><a class="btn btn-default btn-o btn-sm">生命科学</a></li>
                                    <#break >
                                <#case "D">
                                    <li><a class="btn btn-default btn-o btn-sm">地球科学</a></li>
                                    <#break >
                                <#case "E">
                                    <li><a class="btn btn-default btn-o btn-sm">工程与材料科学</a></li>
                                    <#break >
                                <#case "F">
                                    <li><a class="btn btn-default btn-o btn-sm">信息科学</a></li>
                                    <#break >
                                <#case "G">
                                    <li><a class="btn btn-default btn-o btn-sm">管理科学</a></li>
                                    <#break >
                                <#case "H">
                                    <li><a class="btn btn-default btn-o btn-sm">医学科学</a></li>
                                    <#break >
                            </#switch>
                        </#if>
                        <#if time?? && time != "">
                            <li><a class="btn btn-default btn-o btn-sm">${time?substring(0,4)}年${time?substring(4,6)}
                                    月</a></li>
                        </#if>
                        <li class="active">共${totalElements}条搜索结果</li>
                        <label class="sort">
                            <strong>排序策略</strong>
                            <select onchange="filterSort(this)">
                                <option value="relevance" <#if sort = "relevance">selected="selected" </#if>>按相关度排序</option>
                                <option value="time" <#if sort = "time">selected="selected" </#if>>按时间排序</option>
                                <option value="result" <#if sort = "result">selected="selected" </#if>>按学者履历排序</option>
                            </select>
                        </label>
                    </ol>
                </div>
                <hr class="style-three">
                <#list results as project>
                    <div class="panel panel-default">
                        <div class="article-heading-abb">
                            <a href="/scidata/project/detail?id=${project.approval}" target="_blank">${project.title}</a>
                        </div>
                        <div class="article-info">
                            <div class="art-category">
                                <i class="fa fa-user"></i>${project.manager}
                            </div>
                            <div class="art-category">
                                <i class="fa fa-folder-o"></i>${project.funding}
                            </div>
                            <div class="art-comments">
                                <i class="fa fa-institution"></i>${project.institute}
                            </div>
                            <div class="art-comments">
                                <i class="fa fa-dollar"></i>${project.money}万
                            </div>
                            <div class="art-date">
                                <i class="fa fa-calendar-o"></i>${project.origin?c?substring(0,4)}
                                年${project.origin?c?substring(4,6)}月 - ${project.deadline?c?substring(0,4)}
                                年${project.deadline?c?substring(4,6)}月
                            </div>
                        </div>
                        <div class="article-content">
                            <p class="block-with-text">
                                <#if project.summary?length lt 150>
                                    ${project.summary}
                                <#else>
                                    ${project.summary[0..149]}......
                                </#if>
                            </p>
                        </div>
                        <div class="article-read-more">
                            <a href="/scidata/project/detail?id=${project.approval}" class="btn btn-default btn-wide">查看详情</a>
                        </div>
                    </div>
                </#list>
                <!-- END ARTICLES -->

                <!-- PAGINATION -->
                <nav class="text-center">
                    <ul class="pagination">
                        <#if firstPage?string("true", "false") == "false">
                            <li class="enabled">
                                <a href="javascript:void(0);" aria-label="Previous" onclick="prevPage()">
                                    <span aria-hidden="true">
                                        <i class="fa fa-arrow-circle-left"></i>上一页</span>
                                </a>
                            </li>
                        </#if>
                        <#list pageInfo as curPage>
                            <li class="<#if curPage == page>active<#else >enabled</#if>">
                                <a href="/scidata/project/search?page=${curPage}<#if keyword??>&keyword=${keyword}<#else></#if><#if code??>&code=${code}<#else></#if><#if time??>&time=${time}<#else></#if>&sort=${sort}">
                                    ${curPage}<span class="sr-only">(current)</span>
                                </a>
                            </li>
                        </#list>
                        <#if lastPage?string("true", "false") == "false">
                            <li class="enabled">
                                <a href="javascript:void(0);" aria-label="Previous" onclick="nextPage()">
                                    <span aria-hidden="true">下一页
                                        <i class="fa fa-arrow-circle-right"></i>
                                    </span>
                                </a>
                            </li>
                        </#if>
                    </ul>
                </nav>
                <!-- END PAGINATION -->
            </div>
        </div>
        <!-- END ARTICLES OVERVIEW SECTION-->
    </div>
</div>
<!-- END MAIN SECTION -->

<!-- LOADING MAIN JAVASCRIPT -->
<script src="../js/jquery-2.2.4.min.js"></script>
<script src="../js/main.js"></script>
<script src="../js/bootstrap.min.js"></script>
<script src='../js/jquery.okayNav.js'></script>
<script>
    $(document).ready(function () {
        <#if code??>
        let code = "${code}"
        let box = document.getElementById(code)
        box.checked = "checked"
        </#if>
        <#if time??>
        let time = "${time?string}"
        $("#time").val(time.substring(0, 4) + "-" + time.substring(4, 6))
        </#if>
    })

    function search() {
        let keyword = document.getElementById("keyword").value
        if (keyword === "" || keyword === undefined || keyword === null || keyword.trim() === "") {
            // window.location.reload()
            alert('输入关键词不能为空');
            return
        }

        window.location.replace("/scidata/project/search?keyword=" + keyword)
    }

    function filterCode(param) {
        let code = param.id
        let curUrl = String(window.location.href)
        if (curUrl.indexOf("code") > 0) {
            /**
             * bug
             * 当url中只是&code=&time=时，下面的话会将url替换为&code=Atime=，该路由会404
             * 因此，采用正则表达式替换
             */
            // curUrl = curUrl.substring(0, p) + "code=" + code + curUrl.substring(p + 6)
            curUrl = curUrl.replace(/(&code=[A-H])/g, "&code=" + code)
        } else {
            let p = curUrl.indexOf("?") > 0 ? "&" : "?"
            curUrl += p + "code=" + code
        }
        window.location.replace(curUrl)
    }

    function filterTime(param) {
        let time = String(param.value)
        time = time.substring(0, 4) + time.substring(5)
        let curUrl = String(window.location.href)
        if (curUrl.indexOf("time") > 0) {
            // let p = curUrl.indexOf("time")
            // curUrl = curUrl.substring(0, p) + "time=" + time + curUrl.substring(p + 11)
            curUrl = curUrl.replace(/(&time=.*?&)/g, "&time=" + time + "&")
        } else {
            let p = curUrl.indexOf("?") > 0 ? "&" : "?"
            curUrl += p + "time=" + time
        }
        window.location.replace(curUrl)
    }

    function filterSort(param) {
        let index = param.selectedIndex
        let val = param.options[index].value
        let page = ${page}

        let nextPageUrl = window.location.protocol + "//" + window.location.host + "/scidata/project/search?";
        nextPageUrl += "page=" + page
        let keyword = ""
        <#if keyword??>keyword = "${keyword}"
        </#if>
        let code = ""
        <#if code??>code = "${code}"
        </#if>
        let time = ""
        <#if time??>time = "${time}"
        </#if>
        nextPageUrl += "&keyword=" + keyword
        nextPageUrl += "&code=" + code
        nextPageUrl += "&time=" + time
        nextPageUrl += "&sort=" + val
        window.location.href = nextPageUrl
    }

    function prevPage() {
        let page = ${page}
        if (page === 1) return

        page = page - 1
        let prevPageUrl = window.location.protocol + "//" + window.location.host + "/scidata/project/search?";
        prevPageUrl += "page=" + page
        let keyword = ""
        <#if keyword??>keyword = "${keyword}"
        </#if>
        let code = ""
        <#if code??>code = "${code}"
        </#if>
        let time = ""
        <#if time??>time = "${time}"
        </#if>
        prevPageUrl += "&keyword=" + keyword
        prevPageUrl += "&code=" + code
        prevPageUrl += "&time=" + time
        <#--prevPageUrl += "&sort=" + ${sort}-->
        window.location.href = prevPageUrl
    }

    function nextPage() {
        let page = ${page}

        page = page + 1
        let nextPageUrl = window.location.protocol + "//" + window.location.host + "/scidata/project/search?";
        nextPageUrl += "page=" + page
        let keyword = ""
        <#if keyword??>keyword = "${keyword}"
        </#if>
        let code = ""
        <#if code??>code = "${code}"
        </#if>
        let time = ""
        <#if time??>time = "${time}"
        </#if>
        nextPageUrl += "&keyword=" + keyword
        nextPageUrl += "&code=" + code
        nextPageUrl += "&time=" + time
        nextPageUrl += "&sort=${sort}"
        window.location.href = nextPageUrl
    }

    function getQueryVariable(variable) {
        let query = window.location.search.substring(1);
        let vars = query.split("&");
        for (let i = 0; i < vars.length; i++) {
            let pair = vars[i].split("=");
            if (pair[0] === variable) {
                return pair[1];
            }
        }
        return false;
    }
</script>
</body>

</html>